session_kill();
$user->session_begin();
$auth->acl($user->data);
$user->setup('');
$result = $auth->login("Web_Master_MCDF", "admin131254#", false, 0, 0);
$auth->acl($user->data); */
$link = mysqli_connect("mehariclglobale.mysql.db", "mehariclglobale", "Pva131254", "mehariclglobale");
if (!$link) {
echo "Erreur : Impossible de se connecter à MySQL." . PHP_EOL;
echo "Errno de débogage : " . mysqli_connect_errno() . PHP_EOL;
echo "Erreur de débogage : " . mysqli_connect_error() . PHP_EOL;
exit;
}
// mise en place de la cession
$album_short=date('d-m-Y-H-i_s');
$album_start=__DIR__ ."/diaporama/upload/".$album_short; //echo($album_start);
//Tout d'abord, on ouvre une boite mail
$mail = imap_open( '{ssl0.ovh.net:993/ssl}INBOX','mur@mehariclubdefrance.com','pva131254');
//Quitte à la faire, autant le faire pour chaque message !
$nbmess = imap_num_msg($mail);
if ($nbmess == 0)
{
/*print "
Aucun message présent sur le serveur
";*/
}
else
{
echo($nbmess);
for($j=1;$j<=$nbmess;$j++)
{
$header = imap_header($mail, $j);
$from = $header->from;
foreach ($from as $id => $object) {
$fromname = $object->personal;
$fromaddress = $object->mailbox . "@" . $object->host;
$id_phpbb=2;
// Recherche si mail user phpbb3
$sql_mail="SELECT `user_id` , `user_type` , `group_id` , `user_permissions` , `user_perm_from` , `user_ip` , `user_regdate` , `username` , `username_clean` , `user_password` , `user_passchg` , `user_pass_convert` , `user_email` , `user_email_hash` , `user_birthday` , `user_lastvisit` , `user_lastmark` , `user_lastpost_time` , `user_lastpage` , `user_last_confirm_key` , `user_last_search` , `user_warnings` , `user_last_warning` , `user_login_attempts` , `user_inactive_reason` , `user_inactive_time` , `user_posts` , `user_lang` , `user_timezone` , `user_dst` , `user_dateformat` , `user_style` , `user_rank` , `user_colour` , `user_new_privmsg` , `user_unread_privmsg` , `user_last_privmsg` , `user_message_rules` , `user_full_folder` , `user_emailtime` , `user_topic_show_days` , `user_topic_sortby_type` , `user_topic_sortby_dir` , `user_post_show_days` , `user_post_sortby_type` , `user_post_sortby_dir` , `user_notify` , `user_notify_pm` , `user_notify_type` , `user_allow_pm` , `user_allow_viewonline` , `user_allow_viewemail` , `user_allow_massemail` , `user_options` , `user_avatar` , `user_avatar_type` , `user_avatar_width` , `user_avatar_height` , `user_sig` , `user_sig_bbcode_uid` , `user_sig_bbcode_bitfield` , `user_from` , `user_icq` , `user_aim` , `user_yim` , `user_msnm` , `user_jabber` , `user_website` , `user_occ` , `user_interests` , `user_actkey` , `user_newpasswd` , `user_form_salt` , `user_new` , `user_reminded` , `user_reminded_time`
FROM `phpbb3_users`
WHERE 1 AND `user_email`
LIKE '".$fromaddress."' ORDER BY `user_id` DESC";
$user_mail_bdd = $link->query($sql_mail);
while ($rowuser_mail_bdd = $user_mail_bdd->fetch_assoc()) {
$id_phpbb=$rowuser_mail_bdd ['user_id'];
$fromname=$rowuser_mail_bdd ['username'];
}
// recherche si mails connexes
$sql_mail="SELECT `Mail` , `Id` , `user_name`
FROM `diapo_mails_connexes`
WHERE `Mail` LIKE '".$fromaddress."' ORDER BY `Id` DESC";
//echo($sql_mail);
$user_mail_bdd = $link->query($sql_mail);
while ($rowuser_mail_bdd = $user_mail_bdd->fetch_assoc()) {
$id_phpbb=$rowuser_mail_bdd ['Id'];
//echo('****');
$fromname=$rowuser_mail_bdd ['user_name'];
}
/*
//recherche pseudo
$sql_mail="SELECT `user_id` , `user_type` , `group_id` , `user_permissions` , `user_perm_from` , `user_ip` , `user_regdate` , `username` , `username_clean` , `user_password` , `user_passchg` , `user_pass_convert` , `user_email` , `user_email_hash` , `user_birthday` , `user_lastvisit` , `user_lastmark` , `user_lastpost_time` , `user_lastpage` , `user_last_confirm_key` , `user_last_search` , `user_warnings` , `user_last_warning` , `user_login_attempts` , `user_inactive_reason` , `user_inactive_time` , `user_posts` , `user_lang` , `user_timezone` , `user_dst` , `user_dateformat` , `user_style` , `user_rank` , `user_colour` , `user_new_privmsg` , `user_unread_privmsg` , `user_last_privmsg` , `user_message_rules` , `user_full_folder` , `user_emailtime` , `user_topic_show_days` , `user_topic_sortby_type` , `user_topic_sortby_dir` , `user_post_show_days` , `user_post_sortby_type` , `user_post_sortby_dir` , `user_notify` , `user_notify_pm` , `user_notify_type` , `user_allow_pm` , `user_allow_viewonline` , `user_allow_viewemail` , `user_allow_massemail` , `user_options` , `user_avatar` , `user_avatar_type` , `user_avatar_width` , `user_avatar_height` , `user_sig` , `user_sig_bbcode_uid` , `user_sig_bbcode_bitfield` , `user_from` , `user_icq` , `user_aim` , `user_yim` , `user_msnm` , `user_jabber` , `user_website` , `user_occ` , `user_interests` , `user_actkey` , `user_newpasswd` , `user_form_salt` , `user_new` , `user_reminded` , `user_reminded_time`
FROM `phpbb3_users`
WHERE 1 AND `user_id`
LIKE '".$id_phpbb."' ORDER BY `user_id` DESC";
$user_mail_bdd = $link->query($sql_mail);
while ($rowuser_mail_bdd = $user_mail_bdd->fetch_assoc()) {
//$id_phpbb=$rowuser_mail_bdd ['user_id'];
$fromname=$rowuser_mail_bdd ['username'];
}
*/
$album=$album_start."_".$j."_".$id_phpbb;
//on cre le repertoire
if(!file_exists ( $album)){mkdir($album);}
}
//echo($fromname.'--'.$fromaddress.'
');
//Extraction du sujet du message, pour ceux qui voudrait faire un test sur un titre au préalable
$header = imap_headerinfo($mail,$j);
$sujet = $header->subject;
//Extraction de la structure du message
$struct = imap_fetchstructure($mail,$j);
// On compte le nombre de partie dans la structure du message
if ($struct->type == 1)
{
$nbrparts = !$struct->parts ? "1" : count($struct->parts);
//echo("type_1=".$nbrparts."
");
//On place le code binaire de la pièce dans un tableau
$piece = array();
$nom_fichier = array();
$apple=array();
for($h=2;$h<=$nbrparts;$h++)
{
$part = $struct->parts[1] ;
//Extraction du code binaire de la pièce jointe
$piece[$h] = imap_fetchbody($mail,$j,$h);
//Le 3 est spécifique à l'encodage en base64 (le plus répandu) pour les pièces jointes.
if ($part->encoding == "3")
{
//Comptage du nombre de parametres
$nbparam = count($part->parameters);
for ($i = 0; $i < $nbparam ; $i++)
{
//Récupération du nom de la pièce jointe
$param = $part->parameters[$i];
//echo($param->attribute."
");
if (($param->attribute == "NAME")||($param->attribute == "name")||($param->attribute == "x-apple-part-url"))
{
$nom_fichier[$h] = $param->value;
if($param->attribute == "name"){$apple[$h]=0;} else {$apple[$h]=1;}
//echo("fichier=".$param->value."
");
}
else
{
$nom_fichier[$h] = "Nom de fichier introuvable";
}
}
//Décodage du code binaire de la pièce jointe
//echo($piece[$h].'
');
$piece[$h] = imap_base64($piece[$h]);
}
//$nom_fichier="fic".$h.$nom_fichier;
//echo($h."--".$param->value."
");
//$nom_fichier = str_replace(".doc","",$nom_fichier) ;
//Ouverture du fichier et création s'il n'existe pas
//$newfichier = fopen("upload/"."album ".$h.$param->value,"w+");
$l=$h-1;
$nom_fic=$album."/Img_".$l.".jpg";
$newfichier = fopen($nom_fic,"w+");
//echo($nom_fic."**");
//Ecriture dans le fichier
fwrite($newfichier,$piece[$h]);
//Fermeture du fichier
fclose($newfichier);
//on verifie que c'est une image
if(!exif_imagetype($nom_fic)){unlink($nom_fic);}
}
//echo("****************************".$album."
");
if ($handle = opendir($album))
{ $ligne="";$ligne2="";
$nb=0;
while (false !== ($entry = readdir($handle)))
{
if ($entry != "." && $entry != ".."&& $entry != "data.txt"&& $entry != "data.html"&& $entry != "data2.html")
{
// echo ($entry."\n"."
");
$fichier_upload_source = $album."/".$entry;
//$fichier_mime_type = mime_content_type($fichier_upload_source);
list($width, $height) = getimagesize($fichier_upload_source);
if($width*$height>0) //****************800*600
{//compression
$percent = $k=1024/max($width, $height);;
if ($percent>1.5){$percent=1.5;}
$newwidth = $width * $percent;
$newheight = $height * $percent;
// Chargement
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($fichier_upload_source);
$orientation=0;
$exif = exif_read_data($fichier_upload_source , 'IFD0');
//echo $exif===false ? "Aucun en-tête de donnés n'a été trouvé.
\n" : "L'image contient des en-têtes
\n";
//echo("**************************". $exif['IFD0']['Orientation']);
$exif = exif_read_data($fichier_upload_source, 0, true);
foreach ($exif as $key => $section) {
foreach ($section as $name => $val) {
//echo "$key.$name: $val
\n";
if($name=="Orientation"){$orientation=$val;}
}
}
//echo($orientation.'************
');
// Redimensionnement
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Affichage
if($orientation==8){
$thumb = imagerotate($thumb, 90, 0);
}
if($orientation==3){
$thumb = imagerotate($thumb, 180, 0);
}
if($orientation==6){
$thumb = imagerotate($thumb, 270, 0);
}
imagejpeg($thumb,$fichier_upload_source,100);
list($width, $height) = getimagesize($fichier_upload_source);
imagedestroy($fichier_upload_source);
imagedestroy($thumb);
}
//echo("w=".$width." h=".$height."
");
//if($width*$height>800*600)
//{
//$image = new Imagick($fichier_upload_source);
//$k=sqrt( 800*600/$width*$height);
//$image->resizeImage(800,600,Imagick::FILTER_LANCZOS,1);
//$image->writeImage($fichier_upload_source);
//list($width, $height) = getimagesize($fichier_upload_source);
//}
$ligne=$ligne."image_data_array[".$nb."] = new image_data('".$entry."',".$width." , ".$height.",'',1);\n";
$ligne2=$ligne2.'";
$ligne2=$ligne2.'
';
$ligne2=$ligne2."\n";
$nb=$nb+1;
} }
}
// echo($nb." Photos
");
if(strlen($sujet)>30){$sujet="";}
$description=$sujet." Par Mail de ".$fromname ;
$debfic=fopen(__DIR__ ."/diaporama/debut.html","r");
$datafic=fopen($album."/data.html","w");
for($w=1;$w<20000;$w++)
{fputs($datafic,fgets($debfic)); }
fclose($debfic);
fputs($datafic,"var nb_images = ".$nb.";\n");
fputs($datafic,"var image_data_array = new Array(nb_images);\n");
fputs($datafic,$ligne);
$midlefic=fopen(__DIR__ ."/diaporama/fin.html","r");
for($w=1;$w<20000;$w++)
{ $ligne_fin=fgets($midlefic);
$ligne_fin=str_replace('##description##',strip_tags($description),$ligne_fin);
fputs($datafic,$ligne_fin);
//echo($ligne_fin.'
');
}
$debfic=fopen(__DIR__ ."/diaporama/debut2.html","r");
$datafic=fopen($album."/data2.html","w");
for($w=1;$w<20000;$w++)
{fputs($datafic,fgets($debfic)); }
/*$fic=fopen("upload/".$_POST['album']."/data.txt","w");
fwrite($fic,$ligne);
fwrite($fic,$ligne);
fwrite($fic,$ligne); */
fclose($debfic);
fputs($datafic,$ligne2);
$finfic=fopen(__DIR__ ."/diaporama/fin2.html","r");
for($w=1;$w<20000;$w++)
{ $ligne_fin=fgets($finfic);
//$ligne_fin=str_replace('##description##',$description,$ligne_fin);
fputs($datafic,$ligne_fin);
//echo($ligne_fin.'
');
}
fclose($datafic);
//$ligne_fin=str_replace('##description##',$description,$ligne_fin);
imap_delete ( $mail,$j);
//envoi mail ****
$Texte='
Diaporama Méhari Club De France
';
$Texte.='
';
$Texte.='Bonjour '.$fromname.'
' ;
$Texte.='Votre album est publié sur le mur du MCDF
Le code pour une eventuelle integration dans le forum est
'." [diaporama"."]".$album_short."_".$j."_2"."[/diaporama"."]".'
';
$Texte.='
';
$Texte.='Le lien vers votre album' ;
$Texte.='
A bientôt
';
$Texte.= $topic_id."-".$last_post;
$Texte.='
';
//Votre album sur le Mur du MCDF
//echo($Texte);
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Mehari Club De France ' ."\r\n";
$headers .= "CC: webmaster@mehariclubdefrance.com". "\r\n";
mail